import streamlit as st
import pandas as pd

page = st.selectbox('眼镜', ['板材', '金属', '探店'])
if page == '板材':
    df = pd.read_excel('板材眼镜20220208122536.xlsx')
elif page == '金属':
    df = pd.read_excel('金属眼镜20220208122305.xlsx')
elif page == '探店':
    df = pd.read_excel('探店.xlsx')
import collections

data = []
print(df.columns)
for u in df['笔记内容标签'].values:
    if isinstance(u, str) is False:
        continue
    u = eval(u)
    data.extend(u)

import jieba

word = []
for u in df['笔记内容'].values:
    if isinstance(u, str) is False: continue
    word.extend(jieba.lcut(u))


def word2df(data,filter = None):
    counter = collections.Counter(data)
    rows = []
    for word, freq in counter.most_common(100):
        if not filter :
            rows.append((word+4*' ', freq))
        elif filter(word):
            rows.append((word+4*' ', freq))
    res = pd.DataFrame(rows, columns=['标签', '出现次数'])
    return res


button = st.button('查看top tag')
if button:
    res = word2df(data)
    st.dataframe(res)

button2 = st.button('查看top 文本词')
if button2:
    res = word2df(word,lambda x:len(x)>1)
    st.dataframe(res)
